package banking;

public class CheckingAccount extends Account {
    private SavingsAccount protectedBy = null;

    public CheckingAccount(double balance) {
        super(balance);
    }

    public CheckingAccount(double balance, SavingsAccount protect) {
        super(balance);
        this.protectedBy = protect;
    }

    @Override
    public boolean withdraw(double amount) {

        if (balance >= amount) {
            balance -= amount;
            return true;
        } else if (protectedBy != null) {
            if (protectedBy.withdraw(amount - balance)) {
                balance = 0;
                return true;
            }
        }
        return false;
    }
}
